package com.young.manager.controller;

import com.young.common.interf.IBaseController;
import com.young.common.model.ResultData;
import com.young.manager.model.Company;
import com.young.manager.service.CompanyService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("company")
@RestController
@Slf4j
@RequiredArgsConstructor
public class CompanyController implements IBaseController {

  private final CompanyService companyService;

  @GetMapping
  ResultData<?> queryList(
      @RequestParam(required = false) String name,
      @RequestParam(required = false) String principalPhone,
      @RequestParam(required = false) Integer pageNum,
      @RequestParam(required = false) Integer pageSize
  ) {
    pageNum = null == pageNum ? DEFAULT_PAG_ENUM : pageNum;
    pageSize = null == pageSize ? DEFAULT_PAGE_SIZE : pageSize;
    return success(companyService.queryPage(name, principalPhone, pageNum, pageSize));
  }

  @PostMapping("insert")
  ResultData<?> insertCompany(@RequestBody Company company) {
    companyService.insertCompany(company);
    return success();
  }

  @PostMapping("update")
  ResultData<?> updateCompany(@RequestBody Company company) {
    companyService.updateCompany(company);
    return success();
  }

  @PostMapping("updateStatus")
  ResultData<?> updateCompanyStatus(@RequestParam Long id, @RequestParam Integer status) {
    companyService.updateCompanyStatus(id, status);
    return success();
  }

  @PostMapping("delete")
  ResultData<?> deleteCompany(@RequestParam Long id) {
    companyService.deleteCompany(id);
    return success();
  }

}
